import * as http from 'http'
import * as cheerio from 'cheerio';
import * as iconv from 'iconv-lite';

export default class RequestOperation{
    html:string;
    titles:string[];
    startRequest(url:string){
        http.get(url, res=>{
            res.setEncoding('utf-8');
            res.on('data',chunk=>{
                this.html += chunk; 
            })
            res.on('end',()=>{
                let $ = cheerio.load(this.html);

                //根据网页编码，解码
                let data = $('ul.RsetTabCon.nmshow li a b').text()
                let dataBuffer = new Buffer(data);
                let dataByGb2312 = iconv.decode(dataBuffer,'gb2312');

                console.log(dataByGb2312);
            })
        })
    }
}